package yazan.com.pdacollector_android;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.multidex.MultiDex;

import com.blankj.utilcode.util.Utils;
import com.tencent.bugly.crashreport.CrashReport;

import yazan.com.pdacollector_android.db.MyDevOpenHelper;
import yazan.com.pdacollector_android.model.DaoMaster;
import yazan.com.pdacollector_android.model.DaoSession;

public class PDAApplication extends Application {

    private static PDAApplication application;

    private SQLiteDatabase db;
    private DaoSession mDaoSession;


    public static PDAApplication getInstance() {
        return application;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        Utils.init(this);
        configDB();
        CrashReport.initCrashReport(getApplicationContext(), "a8e9efb4a2", true);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }


    private void configDB() {
        MyDevOpenHelper myDevOpenHelper = new MyDevOpenHelper(this,"pda.db",null);
        db = myDevOpenHelper.getWritableDatabase();
        DaoMaster mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }

    public DaoSession getDaoSession(){
        return mDaoSession;
    }

    public SQLiteDatabase getDB(){
        return db;
    }

}
